1. Field of the Invention
The present invention relates generally to a process of compiling an arbitrary file, and in particular, to a method of pre-processing a conditional region during compiling of an arbitrary file.
2. Description of the Related Art
Compiling is a process of transforming a file in a programming language to a file in a machine language. Most program languages support a pre-processing region, which must first be processed during the compiling. The pre-processing region includes macro functions used to increase a user's ability to read or manage multi-version sources, a file insertion command, conditional commands, and the like. For example, the C or C++ languages may provide #define and #undef commands related to a macro function, a #include command related to file insertion, and conditional commands such as a #if syntax, a #ifdef syntax, a #ifndef syntax, a #else syntax, and a #endif command.
If any of the commands described above are included in a pre-processing region when compiling, a terminal having a compiler performs the functions of the command.
A process of compiling conditional commands in a pre-processing region will now be described with reference to FIG. 1. When a compiler of a terminal compiles the file illustrated in FIG. 1, the compiler generates a token list by performing a line scanning process and a tokenizing process on a line-by-line basis from line 101 to line 111. However, when a compiled file is executed, executed lines differ according to whether a conditional syntax of a conditional command is ‘true’ or ‘false’. That is, the terminal executes the #define command contained in line 101, which is a command related to a macro function, so that A=10. The terminal moves to line 103 and executes the #if syntax, which is a conditional command. Since the #if syntax is true, the terminal moves to line 105, executes the printf syntax, and moves to line 107. Since the #if syntax is true, the terminal does not execute the #else syntax contained in line 107 or the printf syntax contained in line 109. The terminal executes the #endif command contained in line 111 and ends the execution.
As described above, when the file illustrated in FIG. 1 is compiled, even though the token list is generated by performing the line scanning process and the tokenizing process with respect to all lines, when the compiled file is executed, only lines 103, 105, and 111 are executed among the lines in a conditional region.
Thus, when a conditional region included in a pre-processing region of a file is compiled, a compiled file is generated by containing lines which will not be executed, resulting in inefficiency of compile. In addition, when the compiled file generated by means of the inefficient compile is executed, it takes a relatively long time to derive an execution result.